
package threads.lockunlock;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;

public class SomeService
{
	private int counter;
	
	private ReentrantLock lock = new ReentrantLock();

	public void doFoo(int amount)
	{
		boolean captured = lock.tryLock();

	}

	public  void doSynchronized(int amount)
	{
		synchronized(this) {
		
		System.out.println(Thread.currentThread().getName());

		try
		{
			TimeUnit.MILLISECONDS.sleep(1000);
		}
		catch (InterruptedException e)
		{
			e.printStackTrace();
		}
		
		System.out.println(Thread.currentThread().getName() + " after waiting");
		
		counter++;
		
		if (amount == 100) 
		throw new RuntimeException();
		
		
		//int res = 10 / amount;
		int res = 0;
		
		//System.out.println("result is " + res);
		
		}
	}

}
